/*
 * @[H]:  Copyright (c) 2021 Phytium Information Technology, Inc. 
 * 
 *  SPDX-License-Identifier: Apache-2.0. 
 * 
 * @Date: 2021-07-20 18:51:58
 * @LastEditTime: 2021-07-22 21:23:00
 * @Description:  Description of file
 * @Modify History: 
 * * * Ver   Who        Date         Changes
 * * ----- ------     --------    --------------------------------------
 */
#ifndef DRIVERS_ETH_F_XMAC_BD_H
#define DRIVERS_ETH_F_XMAC_BD_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "ft_types.h"

/****************************************************************************/
/**
*
* Read the given Buffer Descriptor word.
*
* @param    BaseAddress is the base address of the BD to read
* @param    Offset is the word offset to be read
*
* @return   The 32-bit value of the field
*
* @note
* C-style signature:
*    u32 FXmacBdRead(uintptr BaseAddress, uintptr Offset)
*
*****************************************************************************/
#define FXmacBdRead(BaseAddress, Offset) \
    (*(u32 *)((uintptr)((void *)(BaseAddress)) + (u32)(Offset)))

/*****************************************************************************/
/**
 * Determine the new bit of the receive BD.
 *
 * @param  bd_ptr is the BD pointer to operate on
 *
 * @note
 * C-style signature:
 *    UINTPTR FXmacBdIsRxNew(FXmacBd* bd_ptr)
 *
 *****************************************************************************/
#define FXmacBdIsRxNew(bd_ptr)                      \
    ((FXmacBdRead((bd_ptr), FXMAC_BD_ADDR_OFFSET) & \
      FXMAC_RXBUF_NEW_MASK) != 0U                   \
         ? TRUE                                     \
         : FALSE)

/*****************************************************************************/
/**
 * Determine the wrap bit of the transmit BD which indicates end of the
 * BD list.
 *
 * @param  BdPtr is the BD pointer to operate on
 *
 * @note
 * C-style signature:
 *    u8 FXmacBdGetTxWrap(FXmacBd* BdPtr)
 *
 *****************************************************************************/
#define FXmacBdIsTxWrap(BdPtr)                     \
    ((FXmacBdRead((BdPtr), FXMAC_BD_STAT_OFFSET) & \
      FXMAC_TXBUF_WRAP_MASK) != 0U                 \
         ? TRUE                                    \
         : FALSE)

/*****************************************************************************/
/**
 * Determine the wrap bit of the receive BD which indicates end of the
 * BD list.
 *
 * @param  BdPtr is the BD pointer to operate on
 *
 * @note
 * C-style signature:
 *    u8 FXmacBdIsRxWrap(FXmacBd* BdPtr)
 *
 *****************************************************************************/
#define FXmacBdIsRxWrap(BdPtr)                     \
    ((FXmacBdRead((BdPtr), FXMAC_BD_ADDR_OFFSET) & \
      FXMAC_RXBUF_WRAP_MASK) != 0U                 \
         ? TRUE                                    \
         : FALSE)

    /************************** Constant Definitions *****************************/

/**************************** Type Definitions *******************************/
#ifdef __aarch64__
/* Minimum BD alignment */
#define FXMAC_DMABD_MINIMUM_ALIGNMENT 64U
#define FXMAC_BD_NUM_WORDS 4U
#else
/* Minimum BD alignment */
#define FXMAC_DMABD_MINIMUM_ALIGNMENT 4U
#define FXMAC_BD_NUM_WORDS 2U
#endif

    /**
 * The FXMAC_Bd is the type for buffer descriptors (BDs).
 */
    typedef u32 FXmacBd[FXMAC_BD_NUM_WORDS];

#ifdef __cplusplus
}
#endif

#endif // !